package com.xyy.saas.payment.api.impl;

import com.alibaba.dubbo.config.annotation.Service;
import com.xyy.saas.payment.exception.PaymentException;
import com.xyy.saas.payment.manage.cores.api.OpenAccountApi;
import com.xyy.saas.payment.manage.cores.enums.ResultCodeEnum;
import com.xyy.saas.payment.manage.cores.vo.ResultVO;
import com.xyy.saas.payment.service.OpenAccountService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;

/**
 * @author wangzeqi
 */
@Slf4j
@Service(version = "1.0.0")
@RequiredArgsConstructor
public class OpenAccountApiImpl implements OpenAccountApi {

    private final OpenAccountService openAccountService;

    @Override
    public ResultVO queryUserSettleInfo(String businessIdType, String businessUserId) {
        log.info("OpenAccountApiImpl queryUserInfo businessIdType:{}, businessUserId:{}", businessIdType, businessUserId);
        try {
            if (StringUtils.isBlank(businessIdType) || StringUtils.isBlank(businessUserId)) {
                throw new PaymentException(ResultCodeEnum.PARAM_ERROR);
            }
            return ResultVO.createSuccess(openAccountService.queryUserSettleInfo(businessIdType, businessUserId));
        } catch (PaymentException e) {
            log.error("OpenAccountApiImpl queryUserInfo error.", e);
            ResultVO resultVO = new ResultVO<>();
            resultVO.setCode(e.getErrCode());
            resultVO.setMsg(e.getErrMsg());
            return resultVO;
        } catch (Exception e) {
            log.error("OpenAccountApiImpl queryUserInfo error.", e);
            return ResultVO.createError(e.getMessage());
        }
    }

}
